package com.neiru.pruebas.ar.thread;

import java.util.List;

import com.neiru.pruebas.ar.figure.Cube;

public class LaunchCubeThread extends Thread {
	private Cube cube;
	private float[] direction;
	public boolean stop = false;
	public List<Cube> cubes;
	public LaunchCubeThread(Cube cube, float[] direction, List<Cube> cubes) {
		this.cube = cube;
		this.direction = direction;
		this.cubes = cubes;
	}
	@Override
	public void run() {
		while(!stop) {
			cube.x += (direction[0]/5);
			cube.y += (direction[1]/5);
			cube.z += (direction[2]/5);
			if(cube.z < -100 || cube.z>100) {
				this.cube.destroyed = true;
				stop=true;
			}
			
			for(Cube cube: this.cubes) {
				if(this.cube.isColision(cube)) {
					cube.destroyed = true;
					this.cube.destroyed = true;
					stop = true;
				}
			}
			
			try {
				Thread.sleep(2);
			} catch (InterruptedException e) {
				stop = true;
			}
		}
	}
}
